package com.ruoyi.project.system.house.renovation.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.house.renovation.domain.HouseRenovation;
import com.ruoyi.project.system.house.renovation.service.IHouseRenovationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 房源装修Controller
 * 
 * @author f_baisi
 * @date 2020-08-27
 */
@Controller
@RequestMapping("/system/house/renovation")
public class HouseRenovationController extends BaseController
{
    private String prefix = "system/house/renovation";

    @Autowired
    private IHouseRenovationService houseRenovationService;

    @RequiresPermissions("system/house:renovation:view")
    @GetMapping()
    public String renovation()
    {
        return prefix + "/renovation";
    }

    /**
     * 查询房源装修列表
     */
    @RequiresPermissions("system/house:renovation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HouseRenovation houseRenovation)
    {
        startPage();
        List<HouseRenovation> list = houseRenovationService.selectHouseRenovationList(houseRenovation);
        return getDataTable(list);
    }

    /**
     * 导出房源装修列表
     */
    @RequiresPermissions("system/house:renovation:export")
    @Log(title = "房源装修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HouseRenovation houseRenovation)
    {
        List<HouseRenovation> list = houseRenovationService.selectHouseRenovationList(houseRenovation);
        ExcelUtil<HouseRenovation> util = new ExcelUtil<HouseRenovation>(HouseRenovation.class);
        return util.exportExcel(list, "renovation");
    }

    /**
     * 新增房源装修
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存房源装修
     */
    @RequiresPermissions("system/house:renovation:add")
    @Log(title = "房源装修", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HouseRenovation houseRenovation)
    {
        return toAjax(houseRenovationService.insertHouseRenovation(houseRenovation));
    }

    /**
     * 修改房源装修
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        HouseRenovation houseRenovation = houseRenovationService.selectHouseRenovationById(id);
        mmap.put("houseRenovation", houseRenovation);
        return prefix + "/edit";
    }

    /**
     * 修改保存房源装修
     */
    @RequiresPermissions("system/house:renovation:edit")
    @Log(title = "房源装修", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HouseRenovation houseRenovation)
    {
        return toAjax(houseRenovationService.updateHouseRenovation(houseRenovation));
    }

    /**
     * 删除房源装修
     */
    @RequiresPermissions("system/house:renovation:remove")
    @Log(title = "房源装修", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(houseRenovationService.deleteHouseRenovationByIds(ids));
    }
}
